package cn.ucuser.music.controller;

import cn.ucuser.music.utils.Music;
import com.jfinal.aop.Inject;
import io.jboot.web.controller.JbootController;
import io.jboot.web.controller.annotation.RequestMapping;
import io.jpress.commons.utils.CommonsUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

@RequestMapping(value = "/music", viewPath = "/")
public class JpressAddonMusicController extends JbootController {

    @Inject
    private Music music;

    public void getLrc(){
        String id = getMap();
        if(StringUtils.isBlank(id)){
            return;
        }
        renderJson(music.getLyric(id));
    }

    public void getMp3(){
        String id = getMap();
        if(StringUtils.isBlank(id)){
            return;
        }
        renderJson(music.getMp3(id));
    }

    public void getPicImg(){
        String id = getMap();
        if(StringUtils.isBlank(id)){
            return;
        }
        renderJson(music.getPicImg(id));
    }
    private String getMap(){
        Map<String, String[]> map = getParaMap();
        //处理xss
        CommonsUtils.escapeMap(map);
        return map.get("id")[0];
    }
}
